package ua.org.enginer.controls
{
	import flash.display.DisplayObject;
	
	import mx.containers.TitleWindow;
	import mx.core.Application;
	import mx.core.ClassFactory;
	import mx.events.CloseEvent;
	import mx.events.FlexMouseEvent;
	import mx.managers.PopUpManager;
		
	public class Window extends TitleWindow
	{
		public function Window()
		{
			super();
			addEventListener(FlexMouseEvent.MOUSE_DOWN_OUTSIDE, function():void {
				dispatchEvent(new CloseEvent(CloseEvent.CLOSE))
			})
			showCloseButton = true;
		}
		
		public static function show(component:Class, properties:Object):Window {
			var factory:ClassFactory = new ClassFactory(component)
			
			factory.properties = properties
			
			var window:Window = new Window()
			
			window.addChild(DisplayObject(factory.newInstance()))
			
			PopUpManager.addPopUp(window, Application.application as DisplayObject, true)
			PopUpManager.centerPopUp(window)
			
			window.addEventListener(CloseEvent.CLOSE, function():void {
				PopUpManager.removePopUp(window)
			})
			
			return window
		}
	}
}